package cate.game.play.skill.passive.gem;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.buff.BuffParam;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 使用治疗技能时，有 30% 给自身生成治疗量 32% 的护盾，当生命值低于 50% 提升至 36% ，持续 2 回合
 */
public class 芳华PH extends PassiveHandler {

	private int 概率;

	private double 护盾系数;

	private int 护盾buff;

	private int 检测生命;

	private double 强化系数;

	//概率=3000&护盾系数=3200&护盾buff=？？&检测生命=5000&强化系数=400
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		护盾系数 = args.getWDouble("护盾系数", 0d);
		护盾buff = args.getInt("护盾buff", 0);
		检测生命 = args.getInt("检测生命", 0);
		强化系数 = args.getWDouble("强化系数", 0d);
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.治疗)) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		double rate = 护盾系数;
		if (skill.owner.attr.total().hpCurRate() < 检测生命) {
			rate += 强化系数;
		}
		double v = action.getStat().getTotalHeal(skill.owner.getPid()) * rate;
		if (v <= 0) {
			return;
		}
		skill.owner.buff.tryAddByTid(action, skill.owner, 护盾buff, new BuffParam().buffHpSet(v));
	}
}
